package org.tinygroup.bizframe.action;

import java.util.Enumeration;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;


@Controller()
public class ActionDev {

    @RequestMapping(value = "/{pageId}", method = RequestMethod.GET)
    public String showPageView(@PathVariable String pageId,HttpServletRequest request,Model model) {
    	putParams(request, model);
        return pageId;
    }

	protected void putParams(HttpServletRequest request, Model model) {
		Enumeration itr = request.getParameterNames();
    	while(itr.hasMoreElements()){
    		String name = itr.nextElement().toString();
    		String value =request.getParameter(name);
    		model.addAttribute(name, value);
    	}
	}

    @RequestMapping(value = "/{pageId2}/{pageId}", method = RequestMethod.GET)
    public String showPageView1(@PathVariable String pageId2, @PathVariable String pageId,HttpServletRequest request,Model model) {
    	putParams(request, model);
    	return pageId2 + "/" + pageId;
    }

    @RequestMapping(value = "/{partId1}/{pageId}/{pageId2}", method = RequestMethod.GET)
    public String showPageSubView(@PathVariable String partId1, @PathVariable String pageId, @PathVariable String pageId2,HttpServletRequest request,Model model) {
    	putParams(request, model);
    	return partId1+"/" + pageId + "/" + pageId2;
    }

    @RequestMapping(value = "/{partId1}/{pageId}/{pageId2}/{pageId3}", method = RequestMethod.GET)
    public String showPageSubView2(@PathVariable String partId1, @PathVariable String pageId, @PathVariable String pageId2, @PathVariable String pageId3,HttpServletRequest request,Model model) {
    	putParams(request, model);
    	return partId1+"/" + pageId + "/" + pageId2+"/"+pageId3;
    }
    @RequestMapping(value = "/{partId1}/{pageId}/{pageId2}/{pageId3}/{pageId4}", method = RequestMethod.GET)
    public String showPageSubView3(@PathVariable String partId1, @PathVariable String pageId, @PathVariable String pageId2, @PathVariable String pageId3,@PathVariable String pageId4,HttpServletRequest request,Model model) {
    	putParams(request, model);
    	return partId1+"/" + pageId + "/" + pageId2+"/"+pageId3+"/"+pageId4;
    }
    @RequestMapping(value = "/{partId1}/{pageId}/{pageId2}/{pageId3}/{pageId4}/{pageId5}", method = RequestMethod.GET)
    public String showPageSubView4(@PathVariable String partId1, @PathVariable String pageId, @PathVariable String pageId2, @PathVariable String pageId3,@PathVariable String pageId4,@PathVariable String pageId5,HttpServletRequest request,Model model) {
    	putParams(request, model);
    	return partId1+"/" + pageId + "/" + pageId2+"/"+pageId3+"/"+pageId4+"/"+pageId5;
    }

    @RequestMapping({"", "/"})
    public String dodo() {
        return "index";
    }


}
